package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 *集合的排序
 */
public class SortPoint {
    public static void main(String[] args) {
        List<Point>list=new ArrayList<>();
        list.add(new Point(1,2));
        list.add(new Point(59,344));
        list.add(new Point(34,55));
        list.add(new Point(66,90));
        list.add(new Point(22,78));
        list.add(new Point(87,81));
        System.out.println("list原始数据："+list);




     //jdk1.8时，List集合自身提供了sort方法进行排序，方法需要传入比较器
        list.sort(new Comparator<Point>() {

            public int compare(Point o1, Point o2) {
                return o1.getX()-o2.getX();
            }
        });
        System.out.println("list排序数据后:"+list);







        /*Collections.sort(list, new Comparator<Point>() {
            public int compare(Point o1, Point o2) {
               // return o1.getX()-o2.getX();//x轴升序
                return  o2.getX()- o1.getX();//x轴降序

                // return o2.getY()- o1.getY();//y轴降序
                //return  o1.getY()-o2.getY();//y轴升序

            }
        });

         */














    }
}
